<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
    <% String path=request.getContextPath(); String basePath=request.getScheme() + "://" + request.getServerName() + ":"
        + request.getServerPort() + path + "/" ; %>

        <!DOCTYPE html>
        <html>

        <head>
            <base href="<%=basePath%>">

            <title>sku编号子表</title>

            <meta http-equiv="pragma" content="no-cache">
            <meta http-equiv="cache-control" content="no-cache">
            <meta http-equiv="expires" content="0">
            <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
            <meta http-equiv="description" content="This is my page">
            <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->

        </head>

        <body>
            <%@ include file="/WEB-INF/jsp/common/header.jsp" %>
                <%@ include file="/WEB-INF/jsp/common/loadDiv.jsp" %>

                    <script type="text/javascript">
                        $(function () {
                            if (PUser.superadmin != 1) {
                                $('#freeze').css({ display: 'none' })
                            }
                            $('#startTime').datebox('setValue', getBeforeCurrentDate30Days());
                            $('#endTime').datebox('setValue', getNowFormatDate());
                            bindgrid();
                        });
                    </script>
                    <script>
                        function del(node) {
                            $.ajax({
                                type: "delete",
                                url: 'sale/sku/master/delete?' + 'skuNum=' + skuNum,
                                //                dataType: "xml",
                                success: function (data) {
                                    $.messager.alert('消息', data.msg);
                                    $('#add').window('close');
                                    bindgrid();
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            });
                        }

                        function save() {
                            if (!$('#fm').form('validate')) {
                                return;
                            }
                            var model = {
                                skuNum: $('#skuNum').textbox('getValue'),
                                skuDescription: $('#skuDescription').textbox('getValue'),
                                skuUnit: $('#skuUnit').textbox('getValue'),
                                skuFactory: $('#skuFactory').textbox('getValue'),
                                skuFactoryDescription: $('#skuFactoryDescription').textbox('getValue'),
                                createTime: $('#createTime').textbox('getValue')
                            };
                            $.ajax({
                                type: "post",
                                dataType: "json",
                                url: 'sale/sku/master/save',
                                data: JSON.stringify(model),
                                contentType: "application/json",
                                success: function (data) {
                                    if (data.code != 60200) {
                                        $.messager.alert('消息', data.msg);
                                    } else {
                                        $.messager.alert('消息', data.msg);
                                        let dg = $('#dg');
                                        dg.datagrid('enableFilter');
                                        dg.datagrid('load');
                                        $('#add').window('close');
                                    }
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            })

                        }

                        function editrow() {
                            //编辑用户
                            var row = $('#dg').datagrid('getSelected');
                            if (row) {
                                $('#add').window('open');
                                $('#fm').form('load', row);

                            } else {
                                $.messager.alert('消息', '请选中一条数据');
                            }
                        }
                    </script>
                    <script>
                        /**
                         *  按条件查询报价列表
                         */
                        function selectList() {
                            var startTime = $('#startTime').datebox('getValue')
                            var endTime = $('#endTime').datebox('getValue')
                            // var status = $('#status').combobox('getValue');
                            var dg = $('#dg');
                            dg.datagrid('enableFilter');
                            dg.datagrid('load', {
                                startTime: startTime ? startTime : '',
                                endTime: endTime ? endTime : '',
                                // status: status ? status : ''
                            });
                        }

                        function bindgrid() {
                            var startTime = $('#startTime').datebox('getValue')
                            var endTime = $('#endTime').datebox('getValue')

                            $('#dg').datagrid(
                                {
                                    title: '',
                                    queryParams: {
                                        startTime: startTime,
                                        endTime: endTime
                                    },
                                    url: "sale/sku/master/selectList",
                                    iconCls: 'icon-application',
                                    width: getWidth(0.98),
                                    height: 400,
                                    nowrap: true,
                                    rownumbers: true,
                                    animate: false,
                                    collapsible: false,
                                    clientPaging: false,
                                    remoteFilter: true,
                                    singleSelect: false,
                                    pagination: true,
                                    remoteSort: true,
                                    filterDelay: 0,
                                    columns: [
                                        [{
                                            field: 'ck',
                                            checkbox: true,
                                            width: 100,
                                        },
                                        {
                                            field: 'skuNum',
                                            title: 'sku编码',
                                            sortable: true,
                                            formatter: function (val, rec) {
                                                return val ? unescape(val) : '';
                                            }
                                        }, {
                                            field: 'skuDescription',
                                            title: 'sku描述',
                                            sortable: true,
                                            formatter: function (val, rec) {
                                                return val ? unescape(val) : '';
                                            }
                                        }, {
                                            field: 'skuUnit',
                                            title: '单位',
                                            sortable: true,
                                            formatter: function (val, rec) {
                                                return val ? unescape(val) : '';
                                            }
                                        }, {
                                            field: 'skuFactory',
                                            title: '工厂',
                                            sortable: true,
                                            formatter: function (val, rec) {
                                                return val ? unescape(val) : '';
                                            }
                                        }, {
                                            field: 'skuFactoryDescription',
                                            title: '工厂描述',
                                            sortable: true,
                                            formatter: function (val, rec) {
                                                return val ? unescape(val) : '';
                                            }
                                        }, {
                                            field: 'createTime',
                                            title: '创建时间',
                                            sortable: true,
                                            formatter: function (val, rec) {
                                                return val ? unescape(val) : '';
                                            }
                                        }]],

                                    onLoadSuccess: function () {
                                    },
                                    onDblClickRow: function () {
                                        editrow();
                                    }
                                });
                            $('#dg').datagrid('enableFilter');
                        }
                    </script>
                    <style scoped="scoped">
                        .textbox {
                            height: 20px;
                            margin: 0;
                            padding: 0 2px;
                            box-sizing: content-box;
                        }

                        /*.table tr {
            height: 15px;
        }*/
                    </style>
                    <div class="query_criteria" id="query_criteria">
                        <div style="margin: 5px 0px">
                            <%-- 搜索框 --%>
                                <label style="font-size: 12px;">创建时间：</label> <input class="easyui-datebox"
                                    name="startTime" id="startTime"
                                    data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                    value="" style="width: 150px"> <label style="font-size: 10px;">~</label> <input
                                    class="easyui-datebox" name="endTime" id="endTime"
                                    data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                    style="width: 150px" /> <a id="search" style="margin-left: 30px"
                                    href="javascript:void(0)" class="easyui-linkbutton"
                                    data-options="iconCls:'icon-search'" onclick="selectList()">查询</a>
                                <a id="freeze" style="margin-left: 30px" href="javascript:void(0)"
                                    class="easyui-linkbutton" data-options="iconCls:'icon-search'"
                                    onclick="freeze()">冻结SKU</a>
                        </div>

                        <table id="dg"></table>

                        <div id="add" class="easyui-window" closed="true" modal="true" title="用户信息"
                            style="width: 500px; height: 450px; padding: 10px 20px">
                            <form id="fm" class="ssec-form">
                                <table class="table">
                                    <tr>
                                        <td>
                                            <div class="ssec-label">sku编码：</div>
                                        </td>
                                        <td>
                                            <div class="ssec-text normal">
                                                <input id="skuNum" name="skuNum" class="easyui-textbox"
                                                    data-options="required:true" />
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <div class="ssec-label">sku描述：</div>
                                        </td>
                                        <td>
                                            <div class="ssec-text normal">
                                                <input id="skuDescription" name="skuDescription" class="easyui-textbox"
                                                    data-options="required:true" />
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <div class="ssec-label">单位：</div>
                                        </td>
                                        <td>
                                            <div class="ssec-text normal">
                                                <input id="skuUnit" name="skuUnit" class="easyui-textbox"
                                                    data-options="required:true" />
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <div class="ssec-label">工厂：</div>
                                        </td>
                                        <td>
                                            <div class="ssec-text normal">
                                                <input id="skuFactory" name="skuFactory" class="easyui-textbox"
                                                    data-options="required:true" />
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <div class="ssec-label">工厂描述：</div>
                                        </td>
                                        <td>
                                            <div class="ssec-text normal">
                                                <input id="skuFactoryDescription" name="skuFactoryDescription"
                                                    class="easyui-textbox" data-options="required:true" />
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <div class="ssec-label">创建时间：</div>
                                        </td>
                                        <td>
                                            <div class="ssec-text normal">
                                                <input id="createTime" name="createTime" class="easyui-textbox"
                                                    data-options="required:true" />
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                                <%--<div style="padding: 5px; text-align: right;">
                                    <a class="easyui-linkbutton" onclick="save();" iconcls="icon-save">保存</a>
                        </div>--%>
                        </form>
                    </div>
                    </div>
                    <script>
                        function freeze() {
                            const rows = $('#dg').datagrid('getChecked')
                            if (null == rows || rows.length == 0) {
                                $.messager.alert('提示', '请选择要冻结的SKU')
                                return
                            }
                            for (let i in rows) {
                                let skuNum = rows[i].skuNum
                                $.ajax({
                                    type: 'get',
                                    url: 'sale/sku/master/freeze?skuNum=' + skuNum,
                                    success: function (data) {
                                        if (data.code != 60200) {
                                            $.messager.alert('消息', data.msg);
                                        } else {
                                            $.messager.show({
                                                title: '操作结果',
                                                msg: data.msg,
                                                timeout: 3000,
                                                showType: 'show'
                                            });
                                            let dg = $('#dg');
                                            dg.datagrid('enableFilter');
                                            dg.datagrid('load');
                                        }
                                    },
                                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                                        $.messager.alert('消息', errorThrown);
                                    }
                                })
                            }
                        }
                    </script>
        </body>

        </html>